package com.example.controller;

import com.example.domain.CheckIn;
import com.example.service.CheckInService;
import com.example.utils.AjaxResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

import static com.example.utils.AjaxResult.successData;

@RestController
@RequestMapping("/root")

public class CheckInController {
    @Autowired
    private CheckInService checkInService;

    /** 检查管理 */
    @RequestMapping("/checkIn")
    public AjaxResult checkIn(@RequestParam(defaultValue = "1", value = "page") Integer pageNum,
                              @RequestParam(defaultValue = "10", value = "limit") Integer pageSize,
                              @RequestParam(defaultValue = ""  , value = "id") String usr
    ){
        HashMap<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        if (usr == null || usr.equals("")) {
            map.put("usr","");
            List<CheckIn> checkIns = checkInService.listAll(map);
            PageInfo<CheckIn> page = new PageInfo<>(checkIns);
            return successData(page.getTotal(), checkIns);
        }
        map.put("usr",usr);
        List<CheckIn> checkIns = checkInService.listAll(map);
        PageInfo<CheckIn> page = new PageInfo<>(checkIns);
        return successData(page.getTotal(), checkIns);
    }

}
